<script>
import AddOrUpdate from "@/views/stock/stock-add-or-update.vue";

export default {
  components: {AddOrUpdate},
  data(){
    return{
      dataForm: {
        stockName:'',
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
    }
  },
  mounted () {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      // console.log(this.dataForm.stockName)
      this.$http({
        url: this.$http.adornUrl('/purchase/stock/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'stockName': this.dataForm.stockName,
          'status': 'C001-50',
        })
      }).then((data) => {
        console.log(data.page.list)
        if (data && data.code === 200) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.$http({
        url: this.$http.adornUrl('/purchase/stock/stockStatus/'+id),
        method: 'put',
      }).then(res => {
        console.log(res);
        if (res.code === 200) {
          this.$message({
            message: '下达成功',
            type: 'success'
          })
          this.getDataList()
        }
      }).catch()
    },
    //详情
    selectStock(id){
      this.$router.push({name:"stockDetails",query:{id:id}})
    }
  }
}
</script>

<template>
  <div class="mod-config">
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="stockName"
        header-align="center"
        align="center"
        label="采购计划名称">
      </el-table-column>
      <el-table-column
        prop="stockType"
        header-align="center"
        align="center"
        label="采购类型">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="采购进度">
      </el-table-column>
      <el-table-column
        prop="submitDate"
        header-align="center"
        align="center"
        label="下达时间">
      </el-table-column>
      <el-table-column
        prop="endDate"
        header-align="center"
        align="center"
        label="计划报价截止时间">
      </el-table-column>
      <el-table-column
        prop="enquire.enquireName"
        header-align="center"
        align="center"
        label="对应询价书">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">下达</el-button>
          <el-button type="text" size="small" @click="selectStock(scope.row.id)">打开</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<style scoped lang="scss">

</style>
